package com.aidex.web.controller.api;

import com.aidex.biz.domain.IndexPage;
import com.aidex.biz.domain.ProductInfo;
import com.aidex.biz.service.IndexPageService;
import com.aidex.biz.service.ProductInfoService;
import com.aidex.biz.service.RubbishTypeService;
import com.aidex.biz.service.WxPayService;
import com.aidex.common.core.controller.BaseController;
import com.aidex.common.core.domain.R;
import com.aidex.common.core.domain.entity.Company;
import com.aidex.system.service.CompanyService;
import com.aidex.system.service.SysDictDataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * 小程序首页管理
 *
 * @author sean
 * @email 2074844820@qq.com
 * @date 2022-09-21
 */
@RestController("ApiIndexInfoController")
@RequestMapping("/api/index")
@Api(tags = "小程序首页管理接口")
@Component
public class IndexInfoController extends BaseController {


    @Autowired
    private IndexPageService indexPageService;
    @Autowired
    private SysDictDataService sysDictDataService;
    @Autowired
    private CompanyService companyService;
    @Autowired
    private WxPayService wxPayService;
    @Autowired
    private RubbishTypeService rubbishTypeService;
    @Autowired
    private ProductInfoService productInfoService;


    /**
     * 获取首页配置信息
     *
     * @param companyId 公司ID company-id
     * @return
     */
    @ApiOperation(value = "小程序端-获取首页配置信息")
    @GetMapping("/getIndexList")
    public R<Map<String,Object>> getIndexList(@RequestHeader(name = "company-id") String companyId) {
        IndexPage indexPage=new IndexPage();
        indexPage.setStatus("0");
        indexPage.setCompanyId(companyId);
        Map<String, Object> map = new HashMap<>();
        // index_bottom 底部  type_model 分类  swiper_model 轮播 customer_service 客服 show_type_model
        indexPage.setIndexType("type_model");
        map.put("type_model", indexPageService.findList(indexPage));
        indexPage.setIndexType("swiper_model");
        map.put("swiper_model", indexPageService.findList(indexPage));
        indexPage.setIndexType("show_type_model");
        map.put("show_type_model", indexPageService.findList(indexPage));
        indexPage.setIndexType("index_bottom");
        map.put("index_bottom", indexPageService.findList(indexPage));
        Company company = companyService.get(indexPage.getCompanyId());
        map.put("xcxName", company.getXcxName());
        map.put("companyQrcode", company.getCompanyQrcode());
        map.put("servicePhone", company.getServicePhone());
        map.put("serviceWeChat", company.getServiceWeChat());
        map.put("workTime", company.getWorkTime());
        map.put("shareImage", company.getShareImage());
        map.put("shareName", company.getShareName());
        map.put("businessPhone", company.getBusinessPhone());
        // Map<String,Object> rubbishMap=new HashMap<>();
        ProductInfo productInfo=new ProductInfo();
        productInfo.setShowIndex(0);
        productInfo.setType(0);
        map.put("hotShowType",productInfoService.findPage(productInfo).getList());
        productInfo=new ProductInfo();
        productInfo.setShowIndex(0);
        productInfo.setType(0);
        productInfo.setIsFirst(1);
        map.put("firstProduct",productInfoService.findPage(productInfo).getList());
        productInfo=new ProductInfo();
        productInfo.setShowIndex(0);
        productInfo.setType(0);
        productInfo.setIsMiaosha(1);
        map.put("miaoshaProduct",productInfoService.findPage(productInfo).getList());
        return R.data(map);
    }
    }





